package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
 ID:	liluyan1
 LANG:	JAVA
 TASK:	numtri
 */
public class numtri {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("numtri.in"));
		int res = new numtri().solve(f);
		
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"numtri.out")));
		out.println(res);
		out.close();
		System.exit(0);
	}
	
	private int solve(BufferedReader f) throws IOException {
		int R = read(f);
		int[][] a = new int[R][];
		for (int i=0; i<R; i++) a[i] = read(f, i+1);
		
		int[][] m = new int[R][];
		for (int i=R-1; i>=0; i--) {
			m[i] = new int[R];
			if (i == R-1) {
				for (int j=0; j<R; j++) m[i][j] = a[i][j];
			}
			else {
				for (int j=0; j<i+1; j++) 
					m[i][j] = a[i][j] + Math.max(m[i+1][j], m[i+1][j+1]);
			}
		}
		
		return m[0][0];
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
